	
//创建3个不同上传文件的不同url Map
	var fileUrl = {
			"songFile": url.UPLOAD_MP3,
			"imgFile" : url.UPLOAD_IMG,
			"lyrFile" : url.UPLOAD_LYR
			};
	//为了避免重复上传文件
	var fileUploadStatus = {};

//服务端提交数据
	var songForm = function(){
		
		//json格式:{songName : '大王来巡山'，singer:'贾乃亮'}
		var param = {
				  songName : $("#songName").val(),
				  singer : $("#singer").val(),
				  album : $("#album").val(),
				  fileName : $("#fileToUpload").val(),
				  imageName : $("#imgFileToUpload").val(),
				  lyricName : $("#lyrFileToUpload").val()
				};
		
		$.get(url.NEW_SONG,param, function(data){
			if(data.code == 0){
				layer.msg("添加成功", {icon: 1, time: 1000}, function() {
					$("#inputForm")[0].reset();
					$(".song-msg").html("");
					removeFileUploadStatus();
				});
			}else if(data.code == 1) {
				
			}
		});
	};
	function removeFileUploadStatus() {
		
		for(var status in  fileUploadStatus) {
			delete fileUploadStatus[status];
		}
	}
	var showSong = function(){
		window.location.href = window.url.LIST_SONG;
	};
	 function fileSelected() {
		 
	        var file = $("#fileToUpload")[0].files[0];
	        //alert(file);
	        if (file) {
	          var fileSize = 0;
	          if (file.size > 1024 * 1024)
	            fileSize = (Math.round(file.size * 100 / (1024 * 1024)) / 100).toString() + 'MB';
	          else
	            fileSize = (Math.round(file.size * 100 / 1024) / 100).toString() + 'KB';
	          document.getElementById('fileName').innerHTML = 'Name: ' + file.name;
	          document.getElementById('fileSize').innerHTML = 'Size: ' + fileSize;
	          document.getElementById('fileType').innerHTML = 'Type: ' + file.type;
	          
	          //根据选择的mp3文件名填充歌曲名称,歌手名称
	          fillInput(file.name);
	        }
	      }
	 
	      function fillInput(fileName) {
	    	  
	    	  $.ajax({
	    		  type: "post",
	    		  url: window.url.CONVERT,
	    		  data: {"fileName": fileName},
	    		  async: false,
	    		  success: function(data) {
	    			  $("#songName").val(data.songName);
	    			  $("#singer").val(data.singer);
	    		  }
	    	  });
	      }
	      
	      function uploadFile() {
	    	  //removeFileUploadStatus();
	    	 if(!$("#inputForm").valid()){
	    		 return false;
	    	 }
	        var fd = null;
	        var name = "";
	        var status = "";
	        var url = "";
	        var files = $(":file");
	        var hasError = false;
	        $.each(files, function(index, item){
	        	fd = new FormData();
	        	name = $(item).attr("name");
	        	status = fileUploadStatus[name];
	        	//如何当前文件已上传成功,则跳过，进行下一个文件上传
	        	if(status == "true") 
	        		return true;
	        	url = fileUrl[name];
	        	fd.append(name, item.files[0]);
	        	$.ajax({
					type: 'post',
					url: url,
					data: fd,
					async: false,  
				    cache: false,  
				    contentType: false,  
				    processData: false, 
					success: function(data){
						if(data.code == 0) {
							$(item).next("div").html("");
							fileUploadStatus[name] = "true";
						}
						if(data.code == 1){
							alert("code: " + 1);
							$(item).next("div").append("fdsfsd").show();
							hasError = true;
						}
					}
				});
	        	if(hasError) {
	        		return false;
	        	}
	        });
	        if(!hasError) 
	        	songForm();
	      }
		